//
//  Home_ViewController.m
//  duoduo
//
//  Created by wanghao on 16/10/11.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "Home_ViewController.h"
#import "LXMapView.h"
#import "PoolListTableVC.h"
#import "Poolinfo_ViewController.h"

@interface Home_ViewController ()
{
    LXMapView * homeMap_;
    UIButton *btn;
    NSInteger count;
    UIView * allInView;
}
@end

@implementation Home_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"拼车";
    count = 0;
    [self setRightItem];
    [self initUI];

}

//位置item
-(void)setRightItem
{
    btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];

    //  [btn setImage:[UIImage imageNamed:@"top_navigation_infoicon"] forState:UIControlStateNormal];
    [btn setTitle:@"深圳" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setContentEdgeInsets:UIEdgeInsetsMake(2, 12, 0, -12)];
    [btn setImage:[UIImage imageNamed:@"ditu"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"ditu"] forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(clickRightItem:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
}

//拼车列表初始化
- (void)initUI
{
    allInView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    //allInView.alpha = 0;
    allInView.backgroundColor = [UIColor whiteColor];

    PoolListTableVC * vc = [[PoolListTableVC alloc]init];
    vc.tableView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight-114);
    allInView.alpha = 1;
    [self.view addSubview:allInView];
    [self addChildViewController:vc];
    [allInView addSubview:vc.tableView];
}

//地图初始化
- (void)setMapUI
{
    LXMapView * map = [[LXMapView alloc]initWithMapFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    [self.view addSubview:map];
    map.index = 0;
    homeMap_ = map;
    map.jumpToInfoBlock = ^()
    {
        NSLog(@"111");
        Poolinfo_ViewController * vc = [[Poolinfo_ViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    };
}

//切换视图
- (void)clickRightItem:(UIButton *)sender
{

    count++;
    PoolListTableVC * vc = [[PoolListTableVC alloc]init];
    vc.tableView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight-114);

    if (count % 2 == 1) {
        allInView.alpha = 0;

        [btn setTitle:@"列表" forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"liebiao"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"liebiao"] forState:UIControlStateSelected];

        [vc removeFromParentViewController];
        [vc.tableView removeFromSuperview];
        [self setMapUI];

    }else{

        allInView.alpha = 1;
        [btn setTitle:@"深圳" forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"ditu"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"ditu"] forState:UIControlStateSelected];
        [self.view addSubview:allInView];
        [self addChildViewController:vc];
        [allInView addSubview:vc.tableView];
    }
    
}

@end
